Compile-time rational arithmetic
From Cppreference
| C++ Standard Library | |||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Utilities library | |||||||||||||||||||||||||||||||||||||||||||
| Compile time rational arithmetic | |||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||
[edit] ratio
| Defined in header <ratio>
| ||
| template< intmax_t Num, intmax_t Denom = 1 >
class ratio; | (C++11 feature) | |
The class template ratio provides compile-time rational arithmetic support.
| This section is incomplete |
Several convenience SI typedefs are already provided:
| Defined in header <ratio>
| ||
| typedef std::ratio<1, 1000000000000000000000000> yocto; //see below
typedef std::ratio<1, 1000000000000000000000> zepto; //see below | (C++11 feature) | |
The typedefs yocto, zepto, zetta, yotta are provided only if intmax_t is sufficient to represent the values used to instantiate the templates.
[edit] ratio arithmetic
Several class templates, that perform arithmetic operations on ratio objects at compile-time are provided.
| Defined in header
<ratio> | |||
| adds two ratio objects at compile-time (class template) | ||
| subtracts two ratio objects at compile-time (class template) | ||
| multiplies two ratio objects at compile-time (class template) | ||
| divides two ratio objects at compile-time (class template) | ||
[edit] ratio comparison
Several class templates, that perform comparison operations on ratio objects at compile-time are provided.
| Defined in header
<ratio> | |||
| compares two ratio objects for equality at compile-time (class template) | ||
| compares two ratio objects for inequality at compile-time (class template) | ||
| compares two ratio objects for less than at compile-time (class template) | ||
| compares two ratio objects for less than or equal to at compile-time (class template) | ||
| compares two ratio objects for greater than at compile-time (class template) | ||
| compares two ratio objects for greater than or equal to at compile-time (class template) | ||